package main

import (
	"embed"
	"fmt"
	"log"
	"os"
	"os/user"
	"path"
	"tk-gen/global"

	"github.com/wailsapp/wails/v2"
	"github.com/wailsapp/wails/v2/pkg/options"
	"github.com/wailsapp/wails/v2/pkg/options/assetserver"
)

//go:embed all:frontend/dist
var assets embed.FS

func main() {
	// Get current user
	currentUser, err := user.Current()
	if err != nil {
		log.Fatal(err)
	}
	// Set app directory
	global.AppDir = fmt.Sprintf("%v\\.tk-gen", currentUser.HomeDir)
	global.DataDir = path.Join(global.AppDir, "data")
	if err := os.MkdirAll(global.DataDir, os.ModePerm); err != nil {
		log.Fatal(err)
	}
	// Create an instance of the app structure
	app := NewApp()

	// Create application with options
	err = wails.Run(&options.App{
		Title:     "TK-Gen",
		Width:     800,
		Height:    600,
		MinWidth:  800,
		MinHeight: 600,
		AssetServer: &assetserver.Options{
			Assets: assets,
		},
		OnStartup: app.startup,
		Bind: []interface{}{
			app,
		},
	})

	if err != nil {
		println("Error:", err.Error())
	}
}
